class Solution {
public:
    string solve(string numstr1, string numstr2) {
        int i = numstr1.size()-1;
        int j = numstr2.size()-1;
        int carry = 0;
        int sum = 0;
        string result;

        while(i >= 0 || j >= 0 || carry > 0)
        {
            sum = carry;
            if(i >= 0)
            {
                sum += numstr1[i]-'0';
                i--;
            }
            if(j >= 0)
            {
                sum += numstr2[j]-'0';
                j--;
            }

            carry = sum / 10;

            result.push_back(sum % 10+'0');

        }

        reverse(result.begin(), result.end());
    
        return result;
    }
};


/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    void reorderList(ListNode *head) {
        vector<ListNode*> nodeArr;
        ListNode* tmp = head;
        while(tmp)
        {
            nodeArr.push_back(tmp);
            tmp = tmp->next;
        }

        int left = 0;
        int right = nodeArr.size()-1;

        ListNode dummy(0);
        ListNode* prev = &dummy;
        while(left <= right)
        {
            if(left <= right)
            {
                prev->next = nodeArr[left++];
                prev = prev->next;
            }

            if(left <= right)
            {
                prev->next = nodeArr[right--];
                prev = prev->next;
            }

            prev->next = nullptr;
        }

        head = dummy.next;
    }
};

